package com.demo.common.logger;

import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 重写 Fegin 日志类，对 Info 等级
 * 以 slf4j 替代 feign logging 进行日志打印
 *
 * @author YT
 * @date
 */
@AllArgsConstructor
public class DemoFeignLogger extends feign.Logger {

    private final Logger logger;

    public DemoFeignLogger() {
        this(feign.Logger.class);
    }

    public DemoFeignLogger(Class<?> clazz) {
        this(LoggerFactory.getLogger(clazz));
    }

    public DemoFeignLogger(String name) {
        this(LoggerFactory.getLogger(name));
    }

    /**
     * 根据判断条件可改变 feign 日志的打印等级
     *
     * @param configKey
     * @param format
     * @param args
     */
    @Override
    protected void log(String configKey, String format, Object... args) {
        if (logger.isInfoEnabled()) {
            logger.info(String.format(methodTag(configKey) + format, args));
        }
    }
}
